package com.qsmx.store.app.util;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.qsmx.store.app.R;

/**
 * 文 件 名: DialogUtil.java
 * 描 述: 对话框工具类
 * 创 建 人: dingyu
 * 创建时间: 2015-10-23
 */
@SuppressLint({"NewApi", "InflateParams"})
public class DialogUtil {

    /**
     * 显示自定义提示信息加载对话框
     */
    public static Dialog createLoadingDialog(Activity activity, String message, boolean isCancel) {
        LayoutInflater inflater = LayoutInflater.from(activity);
        View view = inflater.inflate(R.layout.dialog_loading, null);
        TextView tv = (TextView) view.findViewById(R.id.loading_tv);
        tv.setText(message);
        Dialog dialog = new Dialog(activity, R.style.dialog);
        dialog.setContentView(view);
        dialog.setCancelable(isCancel);
        return dialog;
    }

    /**
     * 显示对话框
     */
    public static void showDialog(Dialog dialog) {
        if (null != dialog && !dialog.isShowing()) {
            dialog.show();
        }
    }

    /**
     * 关闭对话框
     */
    public static void closeDialog(Dialog dialog) {
        if (null != dialog && dialog.isShowing()) {
            dialog.dismiss();
        }
    }

}
